﻿using System;
using Midi;

namespace MIDIRemapper.DeviceInterfaces
{
    public enum MidiType
    {
        Control,
        Instrument,
        Pitch_Wheel,
        Note_On,
        Note_Off,
        NotSure
    }

    public static class MidiTypeExtensions
    {
        /// <summary>
        /// Gets a shortenned string representation of this MidiType.
        /// The returned string is not compatable with <seealso cref="string.GetMidiType()">string.GetMidiType()</seealso>.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetUiStringType(this MidiType type)
        {
            string toReturn = "NotSure";
            switch (type)
            {
                case MidiType.Instrument:
                    toReturn = "Program";
                    break;
                case MidiType.Control:
                    toReturn = "Control";
                    break;
                case MidiType.Note_On:
                    toReturn = "NoteOn";
                    break;
                case MidiType.Note_Off:
                    toReturn = "NoteOff";
                    break;
                case MidiType.Pitch_Wheel:
                    toReturn = "PitchWheel";
                    break;
            }
            return toReturn;
        }

        /// <summary>
        /// Gets a string to represent a MIDIType. 
        /// Returned string will be compatable with <seealso cref="string.GetMidiType()">string.GetMidiType()</seealso>.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetStringType(MidiType type)
        {
            string toReturn = "NotSure";
            switch (type)
            {
                case MidiType.Instrument:
                    toReturn = "Program Change";
                    break;
                case MidiType.Control:
                    toReturn = "Control Change";
                    break;
                case MidiType.Note_On:
                    toReturn = "Note On";
                    break;
                case MidiType.Note_Off:
                    toReturn = "Note Off";
                    break;
                case MidiType.Pitch_Wheel:
                    toReturn = "Pitch Wheel Change";
                    break;
            }
            return toReturn;
        }

        /// <summary>
        /// Gets the MidiType associated with this string. 
        /// Returns MidiType.NotSure if the string is not associated
        /// with any MidiType.
        /// </summary>
        public static MidiType GetMidiType(this string s)
        {
            MidiType toReturn = MidiType.NotSure;
            switch (s)
            {
                case "Program Change":
                    toReturn = MidiType.Instrument;
                    break;
                case "Control Change":
                    toReturn = MidiType.Control;
                    break;
                case "Note On":
                    toReturn = MidiType.Note_On;
                    break;
                case "Note Off":
                    toReturn = MidiType.Note_Off;
                    break;
                case "Pitch Wheel Change":
                    toReturn = MidiType.Pitch_Wheel;
                    break;
            }
            return toReturn;
        }
    }
}